package com.hwl.demo10;

import com.hwl.demo10.service.Observer;
import com.hwl.demo10.service.Subject;
import com.hwl.demo10.service.impl.Boss;
import com.hwl.demo10.service.impl.NBAObserver;
import com.hwl.demo10.service.impl.StockObserver;

/**
 * 观察者模式
 *
 * @author sentry
 * @since 2023-03-19
 */
public class Main {

    public static void main(String[] args) {
        Subject boss1 = new Boss("胡汉三");

        Observer employee1 = new StockObserver("魏延", boss1);
        Observer employee2 = new StockObserver("司马懿", boss1);
        Observer employee3 = new NBAObserver("诸葛亮", boss1);

        boss1.attach(employee1);
        boss1.attach(employee2);
        boss1.attach(employee3);

        boss1.detach(employee1);

        boss1.setAction("我胡汉三回来了");
        boss1.notifyEmployee();
    }
}
